/* Copyright (c) 2001 Nextel Communications, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *   - Neither the name of Nextel Communications, Inc. nor the names of its
 *     contributors may be used to endorse or promote products derived from
 *     this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NEXTEL
 * COMMUNICATIONS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.nextel.ui; // Generated package name

import com.nextel.util.Debug;
import com.nextel.util.Logger;
import com.nextel.util.StringUtils;
import com.nextel.util.lwuit.Font;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Graphics;
import pe.com.nextel.idioma.IdiomaManager;
import pe.com.nextel.util.ArrayList;
import pe.com.nextel.util.List;

/**
 * An abstract definition of a screen display.
 * <p>
 * This screen has the following elements:
 * <ul>
 * <p><li>An optional, multi-line title at the top</li>
 * <p><li>If a title is specified, a horizontal line across the width of the
 * screen below the title.</li>
 * <p><li>An area at the bottom of the screen for optional labels above the
 * right and left soft keys, and scroll indicators (see below).</li>
 * <p><li>A horizontal line across the width of the screen, separating the
 * screen body from the soft-key area.</li>
 * <p><li>A body between the title and soft-key area. The body contains the
 * visual elements, such as text, radio buttons, and scroll lists.
 * </ul>
 * <p>
 * If a screen body contains more elements  than can be displayed at one time,
 * the screen will be scrolled vertically as the user navigates to the
 * off-screen elements. This will be indicated by the appearance at the center
 * bottom of the screen (between any soft key labels) of an up-arrow when there
 * are off-screen elements before (above)
 * the currently displayed elements and a
 * down-arrow when there are off-screen elements after (below)
 * the currently displayed elements.
 * @author Glen Cordrey
 * @author Edgard Espinoza
 */
abstract public class OAbstractScreen extends Canvas {
    // The following values are defined so they can be used by
    // {@link com.nextel.ui.OComponent}s without requiring access to the screen
    // the components are contained in

//por edgard
    public boolean pintarMenu = false;
    public List vcomandos;
    public int indiceComandoSeleccionado = 0;
    //agregado edgard
    protected OCommandActionListener comandListener;
    /////////////////////////////////////
//    public OScrollMenu scrollMenu ;
    /* The width in pixels of a screen */
    public static final int WIDTH;
    /* The HEIGHT in pixels of a screen */
    public static final int HEIGHT;
    /* The value of the left key, given by
     * {@link javax.microedition.lcdui.Canvas#getKeyCode Canvas.getKeyCode( Canvas.LEFT)}
     */
    public static final int LEFT_KEY;
    /* The value of the right key, given by
     * {@link javax.microedition.lcdui.Canvas#getKeyCode Canvas.getKeyCode( Canvas.RIGHT)}
     */
    public static final int RIGHT_KEY;
    /* The value of the up key, given by
     * {@link javax.microedition.lcdui.Canvas#getKeyCode Canvas.getKeyCode( Canvas.UP)}
     */
    public static final int UP_KEY;
    /* The value of the down key, given by
     * {@link javax.microedition.lcdui.Canvas#getKeyCode Canvas.getKeyCode( Canvas.DOWN)}
     */
    public static final int DOWN_KEY;
    // no initialize the above values

    static { // create a canvas for the sole purpose of getting its attributes
        Canvas dummy = new Canvas() {

            public void paint(Graphics g) { /* do nothing*/

            }
        };
        WIDTH = dummy.getWidth();
        HEIGHT = dummy.getHeight();
        LEFT_KEY = dummy.getKeyCode(Canvas.LEFT);
        RIGHT_KEY = dummy.getKeyCode(Canvas.RIGHT);
        UP_KEY = dummy.getKeyCode(Canvas.UP);
        DOWN_KEY = dummy.getKeyCode(Canvas.DOWN);
        dummy = null;
    } // static initializer
    // number of pixels to place between a dividing line, such as that below the
    // title or above the soft-keys, and any other visual elements
    protected static final int LINE_SPACER = 1;
    // maximum width of an up or down arrow drawn at the bottom of the screen to
    // indicate vertical scrolling
    private static final int ARROW_MAX_WIDTH =
            OUILook.PLAIN_SMALL_TEXT.charWidth('W');
    // The arrow height is dependent upon the width to ensure the arrow is fully
    // filled. for example, with a height of 5 the arrow is drawn by stacking lines
    // 5, 3, and 1 pixel wide.  This knowledge should rightly be encapsulated in a
    // method in the class that contains drawTriangle, but to save ourselves a
    // method declaration and call we calculate the height here.  Not the best
    // design, but it saves space.
    private static final int ARROW_HEIGHT =
            Math.min(OUILook.PLAIN_SMALL_TITLE.getHeight(), (ARROW_MAX_WIDTH + 1) / 2 + 1);
    // number of pixels to use for a margin around the scrolling arrows
    private static final int ARROW_MARGIN = 2;
    /** Number of pixels to leave at bottom for soft-key commands */
    private static final int BOTTOM_MARGIN = OUILook.PLAIN_SMALL_SOFTKEY.getHeight();
    // the font to use for the title
    private Font titleFont;
    // the title
    private String title;
    // the lines comprising the title
    private String[] titleLines;
    // the number of lines in the title
    private int nbrOfTitleLines;

    // the number of javax.microedition.lcdui.Command objects added to this screen
//    private int commandCount;
    public void setComandListener(OCommandActionListener pcomandListener) {
        comandListener = pcomandListener;
    }

    /**
     * Returns the directions the body can be scrolled in.
     * This should be dynamic depending upon what portion of the body area is
     * displayed.
     *
     * @return The directions that the body area can be scrolled. Should be 0 if
     * all body elements can be displayed at once, but if not it should be an
     * appropriate bitwise or of {@link com.nextel.ui.OComponent#UP} and/or
     * {@link com.nextel.ui.OComponent#DOWN}
     */
    abstract protected int getScrollDirections();

    /**
     * Paints the screen's body, which is all of the components that have been
     * added to the screen.
     *
     * @param g The graphics object to draw to.
     */
    abstract protected void paintBody(Graphics g);

    /**
     * Creates a new <code>OAbstractScreen</code> instance.
     *
     */
    protected OAbstractScreen() { /* do nothing */

    } // OAbstractScreen

    /**
     * Creates a new <code>OAbstractScreen</code> instance.
     *
     * @param title The title for the screen
     * @param titleFont The font to use for the title.
     */
    protected OAbstractScreen(String title, Font titleFont) {
//        if ( Debug.ON ) Logger.dev( "OAbstractScreen.OAbstractScreen ENTERED" );
        setTitle(title, titleFont);
//        if ( Debug.ON ) Logger.dev( "OAbstractScreen.OAbstractScreen EXITTING" );
    } // OAbstractScreen

    /**
     * Creates a new <code>OAbstractScreen</code> instance. This form can be
     * used when the text of the title is created after the screen is
     * instantiated but the number of lines in the title is known beforehand.
     *
     * @param nbrOfTitleLines The number of lines in the title.
     * @param titleFont The font to use for the title.
     */
    protected OAbstractScreen(int nbrOfTitleLines, Font titleFont) {
//        if (Debug.ON) {
//            Logger.dev("OAbstractScreen.OAbstractScreen ENTERED");
//        }
        this.nbrOfTitleLines = nbrOfTitleLines;
        this.titleFont = titleFont;
//        if (Debug.ON) {
//            Logger.dev("OAbstractScreen.OAbstractScreen EXITTING");
//        }
    } // OAbstractScreen

    /**
     * Sets the title to display on the screen.
     *
     * @param title The screen title
     * @param titleFont The font to use for the title
     */
    final public void setTitle(String title, Font titleFont) {
        this.title = title;
        this.titleFont = titleFont;
        if (title != null) {
            titleLines = StringUtils.breakIntoLines(title);
            nbrOfTitleLines = titleLines.length;
        }
    } // setTitle

    /**
     * Gets the row where the screen body begins (below the title line)
     *
     * @return the pixel y coordinate where the screen body begins.
     */
    protected int getBodyRow() {
        return getTitleLineRow() + 1 + LINE_SPACER;
    } // getBodyRow

    /**
     * Gets the height of the body area.
     *
     * @return an <code>int</code> value
     */
    public int getBodyHeight() {
//        if (Debug.ON) {
//            Logger.dev("OAbstractScreen.getBodyHeight CALLED");
//        }
        return getHeight() - getBodyRow() - BOTTOM_MARGIN -
                - 1 /* width of bottom line */;
    } // getBodyHeight

    /**
     * Gets the y-coordinate where the line below the title is drawn.
     *
     * @return an <code>int</code> value
     */
    private int getTitleLineRow() {
        return titleFont != null ? nbrOfTitleLines * titleFont.getHeight() : 0;
    } // getTitleLineRow

    /**
     * Displays the title on the screen
     *
     * @param g The Graphics object to which to write the title
     * @param titleLines The line(s) of the title.
     */
    protected void paintTitle(Graphics g) {
//        if (Debug.ON) {
//            Logger.dev("OAbstractScreen.paintTitle.1 ENTERED");
//        }

        nbrOfTitleLines = titleLines.length;
        com.nextel.util.lwuit.Graphics grap3 = new com.nextel.util.lwuit.Graphics(g);
        // paint the background for the title area
        grap3.setColor(OColor.CABECERA_FONDO);
        grap3.fillRect(0, 0, getWidth(),
                nbrOfTitleLines * titleFont.getHeight());

//        System.out.println("formulario.cabecera==" + nbrOfTitleLines * titleFont.getHeight());

        // Paint the screen title
        grap3.setColor(OColor.CABECERA_TEXTO);
            
        grap3.setFont(titleFont);
        
        for (int idx = 0; idx < nbrOfTitleLines; idx++) { // paint each element of the array on a new row
            grap3.drawString(titleLines[idx], (getWidth() - titleFont.stringWidth(titleLines[idx])) / 2,
                    idx * titleFont.getHeight());

        }

        grap3.setColor(OColor.CABECERA_LINEA);
        if (nbrOfTitleLines > 0) {
            // Now, paint a line below the title
//            grap3.setFont( OUILook.PLAIN_SMALL_TITLE );
            grap3.drawLine(0, getTitleLineRow(), getWidth(), getTitleLineRow());
        }

//        if (Debug.ON) {
//            Logger.dev("OAbstractScreen.paintTitle1. EXITTING");
//        }

    } // paintTitle

    /**
     * Paint sscrolling indicator(s) at the bottom of the screen to indicate that
     * the display can scroll vertically.
     *
     * @param g Graphics context for writing the indicators.
     */
    protected void paintScroller(Graphics g) {
//        System.out.println("paintScroller");
//        if ( Debug.ON ) Logger.dev( "OAbstractScreen.paintScroller ENTERED" );
        int scrollDirections = getScrollDirections();
        int oldColor = grap.getColor();
        grap.setColor(OUILook.BACKGROUND_COLOR);

        if ((scrollDirections & OComponent.UP) > 0) { // draw a triangle indicating the display can be scrolled up
            OComponent.drawTriangle(grap,
                    (getWidth() - ARROW_MAX_WIDTH) / 2 - ARROW_MARGIN,
                    getHeight() - ARROW_HEIGHT,
                    ARROW_MAX_WIDTH, ARROW_HEIGHT,
                    OComponent.UP);
        }
        if ((scrollDirections & OComponent.DOWN) > 0) { // draw a triangle indicating the display can be scrolled down
            OComponent.drawTriangle(grap,
                    (getWidth() + ARROW_MAX_WIDTH) / 2 + ARROW_MARGIN,
                    getHeight() - 1/*spacer*/,
                    ARROW_MAX_WIDTH, getHeight() - ARROW_HEIGHT,
                    OComponent.DOWN);
        }
        grap.setColor(oldColor);
//        if ( Debug.ON ) Logger.dev( "OAbstractScreen.paintScroller EXITTING" );
    } // paintScroller

    /**
     * Adds a <code>javax.microedition.lcdui.Command</code> to the screen.
     * <p>
     * This method is overridden solely as a debugging aid to prevent the addition
     * of both <code>Command</code>s and <code>OSoftKey</code>s to the screen
     * (because doing so is an error, as <code>OSoftKey</code>s will be neither
     * displayed nor enabled if the screen contains a <code>Command</code>).
     * If the code base has been compiled with
     * {@link com.nextel.util.Debug#CODE_ON} <code>= true</code> then this method
     * will throw an {@link com.nextel.ui.OUIError} if a <code>Command</code> is
     * added to screen that contains an <code>OSoftKey</code>. If
     * <code>CODE_ON</code> is false then this method will simply call it's parent
     * method.
     *
     * @param cmd The Command to add to the screen.
     * @deprecated no se usa
     */
    public void addCommand(Command cmd) {
    } // addCommand

    /**
     * Paints the screen to the display
     *
     * @param g The Graphics object to paint to.
     */
    final public void paint(Graphics g) {

//        System.out.println("OABstractScreen.paint");

        // always paint the body first, because if vertical scrolling is required
        // the paint of the top- and/or bottom-most components may overrun the
        // body area, and painting the title (top of screen) and soft keys (bottom
        // of screen) afterwords will overwrite the overrun areas


//        System.out.println("OAbstractScreen.paintBottom ENTERED" );
        if (grap == null) {
            grap = new com.nextel.util.lwuit.Graphics(g);
        }
        
//        System.out.println("Formulario.getHeight==" + getHeight( ));
         
        paintBodyBackground(g);
        paintBody(g);
        if (titleLines != null) {
            paintTitle(g);
        }
        paintBottom(g);

    } // paint
      
     
    /**
     * Paints the background for the body area, overwriting anything else  in the
     * area.
     *
     * @param g The graphics object to draw to.
     */
    protected void paintBodyBackground(Graphics g) {
        //if ( Debug.ON ) Logger.dev( "OAbstractScreen.paintBodyBackground ENTERED" );
//        System.out.println("pintando el background del form");
        
        try {
            g.setColor(OUILook.BACKGROUND_COLOR);
            g.fillRect(0, getBodyRow() - LINE_SPACER,
                    getWidth(), getBodyHeight() + LINE_SPACER);
//        g.drawImage(Image.createImage("/fondo.png"), 0, 0, Graphics.TOP | Graphics.LEFT);
        } catch (Exception e) {
            e.printStackTrace();
        }

        //if ( Debug.ON ) Logger.dev( "OAbstractScreen.paintBodyBackground EXITTING" );
    } // paintBodyBackground
    /**
     * Paints the bottom of the screen, which includes the soft keys and, if
     * vertical scrolling is required, the scroll indicator(s)
     *
     * @param g The Graphics object to paint to.
     */
    com.nextel.util.lwuit.Graphics grap;

    protected void paintBottom(Graphics g) {

        com.nextel.util.lwuit.Graphics grap1 = new com.nextel.util.lwuit.Graphics(g);
        // paint the background
        grap1.setColor(OColor.PIE_FONDO);
//        System.out.println(" ----------------------------- paint bottom , piefondo " + OColor.PIE_FONDO);
        grap1.fillRect(0, getHeight() - BOTTOM_MARGIN, getWidth(), BOTTOM_MARGIN);
        
//        System.out.println("pantalla - boton =" + (getHeight() - BOTTOM_MARGIN));
//        System.out.println("pantalla.BOTTOM_MARGIN =" + BOTTOM_MARGIN);
        //grap1.fillArc(0, getHeight() - BOTTOM_MARGIN, getWidth(), BOTTOM_MARGIN, 0, 360);

        // paint the line above the soft keys
        grap1.setColor(OColor.PIE_LINEA);
//        System.out.println(" ----------------------------- paint bottom , pielinea " + OColor.PIE_LINEA);
        grap1.drawLine(0, getHeight() - BOTTOM_MARGIN - 1,
                getWidth(), super.getHeight() - BOTTOM_MARGIN - 1);

        grap1.setColor(OColor.PIE_TEXTO);

        grap1.setFont(OUILook.PLAIN_SMALL_TEXT);

//modificado por edgard

        if (vcomandos != null) {
            if (!pintarMenu && vcomandos.size() <= 2 && vcomandos.size() > 0) {
                // now paint the keys
                grap1.drawString(((OSoftKey) vcomandos.get(0)).getLabel(), 0, getHeight() - BOTTOM_MARGIN);

                if (vcomandos.size() == 2) {
                    grap1.drawString(((OSoftKey) vcomandos.get(1)).getLabel(), getWidth() - OUILook.PLAIN_SMALL_SOFTKEY.stringWidth(((OSoftKey) vcomandos.get(1)).getLabel()), getHeight() - BOTTOM_MARGIN);
                }
                
            } else if (!pintarMenu && vcomandos.size() > 2) {

                grap1.drawString(((OSoftKey) vcomandos.get(0)).getLabel(), 0, getHeight() - BOTTOM_MARGIN);

                grap1.drawString("MENU", getWidth() - OUILook.PLAIN_SMALL_SOFTKEY.stringWidth("MENU"), getHeight() - BOTTOM_MARGIN);

            }
//        repaintSoftKeys = false;
        }

        paintScroller(g);

        ////////////////////////////
        //por edgard
        if (vcomandos != null && pintarMenu && vcomandos.size() > 2) {
            paintMenuSoftKey(g);
        }
        ////////////////////////////////
//        if ( Debug.ON ) Logger.dev( "OAbstractScreen.paintSoftKeys EXITTING" );
    } // paintBottom

    //por edgard
    public void indiceComandoSeleccionado(int keyCode) {

        if (DOWN_KEY == keyCode) {
            indiceComandoSeleccionado =
                    vcomandos.size() == indiceComandoSeleccionado + 1
                    ? 0 : indiceComandoSeleccionado + 1;
        }

        if (UP_KEY == keyCode) {
            indiceComandoSeleccionado =
                    indiceComandoSeleccionado == 0
                    ? vcomandos.size() - 1 : indiceComandoSeleccionado - 1;
        }
    }

   
    public void paintMenuSoftKey(Graphics g) {

        //String cancelar = "Cancelar";
        String cancelar = IdiomaManager.getInstance().getMensaje(IdiomaManager.JAVA_CANCELAR);        
        String seleccionar = IdiomaManager.getInstance().getMensaje(IdiomaManager.JAVA_SELECCION);
        
        com.nextel.util.lwuit.Graphics grap2 = new com.nextel.util.lwuit.Graphics(g);

        grap2.setFont(OUILook.PLAIN_SMALL_TEXT);
        grap2.drawString(cancelar , 0, getHeight() - BOTTOM_MARGIN);
        grap2.drawString(seleccionar, getWidth() - OUILook.PLAIN_SMALL_SOFTKEY.stringWidth(seleccionar), getHeight() - BOTTOM_MARGIN);

        int alturaMenu = 0;
        int anchoMenu = 60;

        /////////////////////////////////////////////////////////////////////////
        int BORDER = 2;
        int sizeComandos = vcomandos.size();

        int altoTexto = grap2.getFont().getHeight();
        alturaMenu = sizeComandos * altoTexto + 2;

        g.setColor(OColor.CABECERA_FONDO);

        g.fillRect(getWidth() - anchoMenu, super.getHeight() - BOTTOM_MARGIN - BORDER - alturaMenu, anchoMenu, alturaMenu);

        g.setColor(OColor.CABECERA_TEXTO);
        g.drawLine(getWidth() - anchoMenu, getHeight() - BOTTOM_MARGIN - BORDER,
                getWidth() - anchoMenu, super.getHeight() - BOTTOM_MARGIN - BORDER - alturaMenu);

        //linea horizontal superior
        g.drawLine(getWidth() - anchoMenu, super.getHeight() - BOTTOM_MARGIN - BORDER - alturaMenu,
                getWidth(), super.getHeight() - BOTTOM_MARGIN - BORDER - alturaMenu);
        //////////////////////////////////////////////////////////////////////

        g.setColor(OColor.DK_GRAY);
        

        for (int i = 0; i < vcomandos.size(); i++) {
//            System.out.println("dibujando la lista de la derecha de menu");
            
            
            if (indiceComandoSeleccionado == i) {
                 
                grap2.setFont(OUILook.PLAIN_SMALL_SOFTKEY);
                 
                g.setColor(OColor.LISTA_ITEM_SELECTED);

                g.fillRect(getWidth() - anchoMenu + BORDER,
                        super.getHeight() - BOTTOM_MARGIN - alturaMenu + i * (OUILook.PLAIN_SMALL_TEXT.getHeight()), anchoMenu, grap2.getFont().getHeight());
            
                grap2.setColor(OColor.TRANSPARENT);

            } else {
                grap2.setFont(OUILook.PLAIN_SMALL_TEXT);
                
                grap2.setColor(OColor.DK_GRAY);
            }

            OSoftKey cmd = (OSoftKey) vcomandos.get(i);

            grap2.drawString(cmd.getLabel(),
                    getWidth() + BORDER - anchoMenu,
                    super.getHeight() - BOTTOM_MARGIN - alturaMenu + OUILook.PLAIN_SMALL_TEXT.getHeight() + i * (OUILook.PLAIN_SMALL_TEXT.getHeight()) - BOTTOM_MARGIN);

        }

    }

    public void addSoftKey(OSoftKey softKey, int position) {

        if (vcomandos == null) {
            vcomandos = new ArrayList();
        }
        vcomandos.add(softKey);

//        if ( Debug.ON ) Logger.dev( "OAbstractScreen.addCommand EXITTING" );
    } // addCommand

    public void addSoftKey(OSoftKey softKey) {

        if (vcomandos == null) {
            vcomandos = new ArrayList();
        }
        vcomandos.add(softKey);
//            repaintSoftKeys = true;
    }

    /**
     * Removes the current soft key. If the stack of soft keys for the indicated
     * <code>position</code> contains another key it will be enabled, meaning it's
     * label will be displayed above the soft key and pressing the soft key will
     * initiated the designated action.
     *
     * @param position The position of the soft key - either
     * {@link javax.microedition.lcdui.Graphics#RIGHT} or
     * {@link javax.microedition.lcdui.Graphics#LEFT}.  No soft key will be added
     * if an invalid value is supplied, but no exception will be thrown.
     */
    public void removeSoftKey(int position) {
//        System.out.println("OAbstractScreen.removeSoftKey ENTERED" );
//
////        if ( position == Graphics.LEFT ) {
        if (vcomandos != null) {
            vcomandos.remove(position);
        }

//
//        if ( Debug.ON ) Logger.dev( "OAbstractScreen.removeSoftKey EXITTING" );
    } // removeSoftKey

    public void removeSoftKey(OSoftKey oSoftKey) {
        if (vcomandos != null) {
            for (int i = 0; i < vcomandos.size(); i++) {
                  if(oSoftKey == (OSoftKey)vcomandos.get(i)){
                        vcomandos.remove(i);
                  }

            }
        }
    }

    /**
     * Processes a press of a key.
     * <p>
     * Any {@link java.lang.Throwable} that is thrown within the thread the
     * processes the key press and which is not caught and consumed will cause the
     * current screen to be replaced by a screen that shows the exception.
     * <p>
     * If {@link com.nextel.util.Debug#LOG_MEM} is <code>true</code> and the
     * push-to-talk key
     * was pressed, a screen will be displayed showing the amount of free and used
     * memory available currently and at each previous such press of the
     * push-to-talk button.
     * The content of this screen is described in
     * {@link #showMem( OAbstractScreen ) }
     *
     * @param keyCode The code of the pressed key.
     */
    public void keyPressed(int keyCode) {
//        System.out.println("OAbstractScreen.keyPressed=" + keyCode);
        try {

            if (comandListener != null && vcomandos != null) {

                if (keyCode == OSoftKey.LEFT && vcomandos.size() > 0) {
                    comandListener.performAction((OSoftKey) vcomandos.get(0));
                } else if (keyCode == OSoftKey.RIGHT && vcomandos.size() > 1) {
                    comandListener.performAction((OSoftKey) vcomandos.get(1));
                }
            }

        } catch (Throwable ex) {
            Logger.ex(ex);
//            displayEx( ex, null );
        }
//        if ( Debug.ON ) Logger.dev( "OAbstractScreen.keyPressed EXITTING" );
    } // keyPressed

    public void clearAll() {
        pintarMenu = false;
        if (vcomandos != null) {
            vcomandos.clear( );
            vcomandos = null;
        }
        titleFont = null;
        titleLines = null;
        comandListener = null;
//        System.gc( );

    }

    protected void keyRepeated(int key) {
    }
} // OAbstractScreen

 

 
